<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:rich="http://richfaces.org/rich"
  xmlns:zanata="http://java.sun.com/jsf/composite/zanata"
  template="/WEB-INF/template/template.xhtml">

  <f:metadata>
    <f:viewParam name="slug" value="#{projectHome.slug}"/>
    <f:viewParam name="slug" value="#{projectHomeAction.slug}"/>
    <f:event type="preRenderView" listener="#{projectHome.initialize}"/>
  </f:metadata>

<ui:define name="page_title">
  #{msgs['jsf.Projects']} - #{projectHome.instance.name}
</ui:define>

<ui:define name="center_content">
<script type="text/javascript">
  //<![CDATA[
  jQuery(function () {
    crossroads.addRoute(':pre*:/project/view/{slug}/settings/{subSection}:?query:',
      function (pre, slug, subSection, query) {
        zanata.tabs.activate(jQuery('#settings_tab'));
        subSection = subSection || 'general';
        subSection = validateTab("#settings-" + subSection + '_tab', subSection, 'general');
        zanata.tabs.activate(jQuery('#settings-' + subSection + "_tab"));
      });

    crossroads.addRoute(':pre*:/project/view/{slug}/:section::?query:',
      function (pre, slug, section, query) {
        section = section || 'versions';
        // maintainers tab is replaced with people tab, so links to maintainers
        // tab should direct to the people tab
        if (section === 'maintainers') {
          section = 'people';
        }
        section = validateTab('#' + section + "_tab", section, "versions");
        zanata.tabs.activate(jQuery('#' + section + "_tab"))
      });

    updateStateFromUrl();
    renderStatistics();
  });
  //]]>

</script>
<div id="projectsWrapper">
  <ui:fragment
    rendered="#{identity.hasPermission(projectHome.instance, 'update')}">
    <zanata:confirm-modal id="exportTMXVersionModal"
      title="#{msgs['jsf.iteration.ExportTMXIter']}"
      message="#{msgs['jsf.ConfirmExportTMXIter']}"
      onresponse="onExportTMXVersionResponse" />

    <script type="application/javascript">
      var selectedVersion;
      function setSelectedVersion(version) {
        selectedVersion = version;
      }
      function onExportTMXVersionResponse(exp) {
        if (exp) {
          window.open("#{request.contextPath}/rest/tm/projects/#{projectHomeAction.slug}/iterations/" + selectedVersion);
        }
        zanata.modal.hide('#exportTMXVersionModal');
      }
    </script>


  </ui:fragment>

  <h:form styleClass="l--push-bottom-0">
    <a4j:jsFunction name="refreshStatistics" status="statistic-loader"
      limitRender="true"
      render="versions_form"
      oncomplete="refreshTooltip('#{rich:clientId('versions_form')}')"
      action="#{projectHomeAction.resetPageData}"/>

    <a4j:jsFunction name="renderStatistics" status="statistic-loader"
      oncomplete="refreshTooltip('#{rich:clientId('versions_form')}')"
      limitRender="true"
      render="versions_form"
      action="#{projectHomeAction.setPageRendered(true)}"/>

    <a4j:jsFunction name="resetProjectMembers"
      render="people-size,people_form" limitRender="true"
      action="#{projectHomeAction.clearCachedMembershipData}"/>

  </h:form>
</div>

<div class="g u-fullWidth">
  <div class="g__item w--1-m w--3-8-l w--1-3 l--push-bottom-half">
    <p class="txt--meta l--push-all-0">
      <a href="#{request.contextPath}/dashboard/projects">
        #{msgs['jsf.Projects']}
      </a>
    </p>

    <h:panelGroup layout="block"  styleClass="media l--push-bottom-half" id="project-info">
      <div class="media__body">
        <h1 class="l--push-all-0">
          <zanata:project-label project="#{projectHome.instance}"/>
        </h1>

        <p class="txt--understated">
          <ui:fragment
            rendered="#{not empty projectHome.instance.description}">
            #{projectHome.instance.description}
          </ui:fragment>
        </p>
      </div>

      <ui:fragment
        rendered="#{not empty projectHome.instance.sourceCheckoutURL or not empty projectHome.instance.sourceViewURL}">
        <div class="d--top l--push-top-half l--pad-top-half">
          <h2 class="delta headding--secondary l--push-top-0">
            <i
              class="i--left i--source"></i> #{msgs['jsf.project.SourceCode']}
          </h2>

          <ul class="list--no-bullets txt--meta l--push-top-quarter">
            <ui:fragment
              rendered="#{not empty projectHome.instance.sourceViewURL}">
              <li>
                <span class="list__title">
                  #{msgs['jsf.project.HomePage']}:
                </span>
                <a href="#{projectHome.instance.sourceViewURL}" target="_blank">
                  #{projectHome.instance.sourceViewURL}<i
                  class="i--small i--right i--external-link txt--neutral"></i>
                </a>
              </li>
            </ui:fragment>
            <ui:fragment
              rendered="#{not empty projectHome.instance.sourceCheckoutURL}">
              <li>
                <div class="bx--table">
                  <div class="bx--table__cell txt--nowrap">
                    <span class="list__title">
                      #{msgs['jsf.project.Repository']}:
                    </span>
                  </div>
                  <div
                    class="bx--table__cell w--1 w--1-s l--pad-left-quarter h--1">
                    <input type="text"
                      class="list__item__info form__input--copyable js-form__input--copyable"
                      readonly="readonly"
                      value="#{projectHome.instance.sourceCheckoutURL}"/>
                  </div>
                </div>
              </li>
            </ui:fragment>
          </ul>
        </div>
      </ui:fragment>
    </h:panelGroup>

    <ui:fragment rendered="#{identity.loggedIn}">
      <ui:param name="activities"
        value="#{projectHomeAction.getProjectLastActivity()}"/>

      <h:panelGroup layout="block"  styleClass="panel l--push-top-half" rendered="#{not empty activities}">
        <div class="panel__header">
          <h2 class="panel__heading--small">
            #{msgs['jsf.YourLastActivity']}
          </h2>
        </div>
        <div class="l--pad-all-half">
          <ui:repeat value="#{activities}" var="activity">
            <div class="txt--meta">
              <zanata:activity-entry value="#{activity}"/>
            </div>
          </ui:repeat>
        </div>
      </h:panelGroup>
    </ui:fragment>

</div>
<div class="g__item w--1-m w--5-8-l w--2-3">
  <div class="tabs--lined js-tabs">
    <ul class="tabs__nav js-tabs-nav">
      <li>
        <a id="versions_tab"
          href="#{request.contextPath}/project/view/#{projectHomeAction.slug}/versions"
          class="js-url-mod" data-content="#versions">
          <i class="i i--version"></i>
              <span class="is-hidden--s i__text--right">
                #{msgs['jsf.Versions']}
                <h:panelGroup styleClass="txt--neutral" id="versions-size">
                  #{projectHomeAction.getProjectVersions().size()}
                </h:panelGroup>
              </span>
        </a>
      </li>
      <li>
        <a id="people_tab"
          href="#{request.contextPath}/project/view/#{projectHomeAction.slug}/people"
          class="js-url-mod" data-content="#people">
          <i class="i i--users"></i>
              <span class="is-hidden--s i__text--right">
                #{msgs['jsf.People']}
                <h:panelGroup styleClass="txt--neutral" id="people-size">
                  #{projectHomeAction.allMembers.size()}
                </h:panelGroup>
              </span>
        </a>
      </li>
      <ui:fragment rendered="#{identity.loggedIn}">
        <li>
          <div class="link zeta">
            <a id="glossary_tab" href="#{request.contextPath}/glossary/project/#{projectHomeAction.slug}">
             <i class="i i--glossary"></i>
             <span class="is-hidden--s i__text--right">
                #{msgs['jsf.Glossary']}
                <span class="txt--neutral" id="glossary-size">
                  #{projectHomeAction.getGlossarySize()}
                </span>
             </span>
            </a>
          </div>
        </li>
      </ui:fragment>
      <li>
        <a id="about_tab"
          href="#{request.contextPath}/project/view/#{projectHomeAction.slug}/about"
          class="js-url-mod" data-content="#about">
          <i class="i i--info"></i>
            <span class="is-hidden--s i__text--right">
              #{msgs['jsf.project.About']}
            </span>
        </a>
      </li>
      <ui:fragment
        rendered="#{identity.hasPermission(projectHome.instance, 'update')}">
        <li class="tab__end">
          <div
            class="dropdown dropdown--tab dropdown--small dropdown--right dropdown--inline js-dropdown">
            <a class="dropdown__toggle js-dropdown__toggle" href="#"
              title="#{msgs['jsf.tooltip.MoreActions']}">
              <i class="i i--ellipsis"></i>
            </a>
            <ul class="dropdown__content js-dropdown__content"
              role="content" aria-labelledby="dropdownContent">
              <li>
                <a href="#" id="exportTMXProjectLink" class="i__item--right"
                  onclick="toggleTMXExportModal(true); return false">
                  #{msgs['jsf.ExportTMXProject']}<i
                    class="i i--export i__item__icon"></i>
                </a>
              </li>
            </ul>
          </div>
        </li>
        <li class="tab__end">
          <a id="settings_tab"
            href="#{request.contextPath}/project/view/#{projectHomeAction.slug}/settings"
            class="js-url-mod" data-content="#settings"
            title="#{msgs['jsf.project.ProjectSettings']}">
            <span class="is-hidden--s i__text--left">
              #{msgs['jsf.Settings']}
            </span>
            <i class="i i--settings"></i>
          </a>
        </li>
      </ui:fragment>
    </ul>

    <ul class="tabsContent panels__container js-tabs-content l--push-top-1">
      <li id="versions">
        <ui:include
          src="/WEB-INF/layout/project/versions-tab.xhtml"/>
      </li>

      <li id="people">
        <ui:include src="/WEB-INF/layout/project/people-tab.xhtml"/>
      </li>

      <li id="about">
        <h:panelGroup layout="block"  id="project-about">
          <div id="home-content-rendered" class="prose">
            <h:outputText
              rendered="#{not empty projectHome.instance.homeContent}"
              value="#{projectHome.aboutHtml}" escape="false" />
          </div>
          <ui:fragment rendered="#{empty projectHome.instance.homeContent}">
            #{msgs['jsf.project.NoHomeContent']}
          </ui:fragment>
        </h:panelGroup>
      </li>

      <ui:fragment
        rendered="#{identity.hasPermission(projectHome.instance, 'update')}">
        <li id="settings">
          <ui:include
            src="/WEB-INF/layout/project/settings-tab.xhtml"/>
        </li>
      </ui:fragment>
    </ul>

    </div>
  </div>
</div>
</ui:define>
</ui:composition>
